#!/usr/bin/env python

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'manage_form.ui'
#
# Created: Thu Apr 30 02:34:51 2009
#      by: The PyQt User Interface Compiler (pyuic) 3.17.6
#
# WARNING! All changes made in this file will be lost!


from qt import *
from add_admin_form import *
from search_admin_form import *
from delete_admin_form import *
import anydbm

class manage_form(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("Manage_form")



        self.groupBox6 = QGroupBox(self,"groupBox6")
        self.groupBox6.setGeometry(QRect(10,10,380,290))

        self.admin_db_info_txt = QTextEdit(self.groupBox6,"admin_db_info_txt")
        self.admin_db_info_txt.setReadOnly(1)
        self.admin_db_info_txt.setGeometry(QRect(10,20,360,260))

        self.groupBox7 = QGroupBox(self,"groupBox7")
        self.groupBox7.setGeometry(QRect(400,10,160,290))

        self.add_admin_btn = QPushButton(self.groupBox7,"add_admin_btn")
        self.add_admin_btn.setGeometry(QRect(10,30,140,41))

        self.search_admin_btn = QPushButton(self.groupBox7,"search_admin_btn")
        self.search_admin_btn.setGeometry(QRect(10,80,140,41))

        self.delete_admin_btn = QPushButton(self.groupBox7,"delete_admin_btn")
        self.delete_admin_btn.setGeometry(QRect(10,130,140,41))

        self.show_DB_btn = QPushButton(self.groupBox7,"show_DB_btn")
        self.show_DB_btn.setGeometry(QRect(10,180,140,41))

        self.exit_ctrlpl_btn = QPushButton(self.groupBox7,"exit_ctrlpl_btn")
        self.exit_ctrlpl_btn.setGeometry(QRect(10,230,140,41))

        self.languageChange()

        self.resize(QSize(571,307).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.connect(self.add_admin_btn,SIGNAL("clicked()"),self.add_admin_btn_clicked)
        self.connect(self.search_admin_btn,SIGNAL("clicked()"),self.search_admin_btn_clicked)
        self.connect(self.delete_admin_btn,SIGNAL("clicked()"),self.delete_admin_btn_clicked)
        self.connect(self.show_DB_btn,SIGNAL("clicked()"),self.show_DB_btn_clicked)
        self.connect(self.exit_ctrlpl_btn,SIGNAL("clicked()"),self.exit_ctrlpl_btn_clicked)


    def languageChange(self):
        self.setCaption(self.__tr("Manager Cotrol Panel"))
        self.groupBox6.setTitle(self.__tr("Adminstrator Info"))
        self.groupBox7.setTitle(self.__tr("Manager control panel"))
        self.add_admin_btn.setText(self.__tr("&Add admin"))
        self.add_admin_btn.setAccel(QKeySequence(self.__tr("Alt+A")))
        self.search_admin_btn.setText(self.__tr("&Search admin"))
        self.search_admin_btn.setAccel(QKeySequence(self.__tr("Alt+S")))
        self.delete_admin_btn.setText(self.__tr("&Delete admin"))
        self.delete_admin_btn.setAccel(QKeySequence(self.__tr("Alt+D")))
        self.show_DB_btn.setText(self.__tr("&Show me DB"))
        self.show_DB_btn.setAccel(QKeySequence(self.__tr("Alt+S")))
        self.exit_ctrlpl_btn.setText(self.__tr("&Exit"))
        self.exit_ctrlpl_btn.setAccel(QKeySequence(self.__tr("Alt+E")))


    def add_admin_btn_clicked(self):
        """
        manager_login_button_clicked(self):
            this function display the admin window
        """
        add_admin = add_admin_form()
        add_admin.show()
        add_admin.exec_loop()

    def search_admin_btn_clicked(self):
        """
        search_admin_btn_clicked(self):
            this functiion display the search admin window
        """
        search_admin = search_admin_form()
        search_admin.show()
        search_admin.exec_loop()

    def delete_admin_btn_clicked(self):
        """
        delete_admin_btn_clicked(self):
            this function display the delete admin window
        """
        delete_admin = delete_admin_form()
        delete_admin.show()
        delete_admin.exec_loop()

    def show_DB_btn_clicked(self):
        """
        show_DB_btn_clicked(self):
            this function display the current admins database
        """
        admin_db = anydbm.open('Admin_Accounts','rw')
        self.admin_db_info_txt.clear()
        self.admin_db_info_txt.append("Admin"+"\t\t"+"Password")
        self.admin_db_info_txt.append("----------------------------------------")
        for key,value in admin_db.iteritems():
            self.admin_db_info_txt.append(key+"\t\t"+value)

    def exit_ctrlpl_btn_clicked(self):
        Message = 'Are you sure you want to exit!'
        reply = QMessageBox.information(self,"Question!",Message,QMessageBox.Yes,QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.hide()
        else:
            pass

    def __tr(self,s,c = None):
        return qApp.translate("Mnage_form",s,c)
